package be.fedict.eid.diagnostics.system.windows;

import java.util.Iterator;
import java.util.List;

import be.fedict.eid.diagnostics.system.DeviceManager;
import be.fedict.eid.diagnostics.system.data.Device;
import be.fedict.eid.diagnostics.system.windows.jna.DeviceHandler;


public class WindowsDeviceManager implements DeviceManager {	
	
	
	public List<Device> getAllDevices() {
		try {
			return DeviceHandler.getAllDevices();
			
		} catch (Exception e) {
			return null;
		}
	}
	
	public List<Device> getSmartCardReaders() {
		try {
			return lookupDevices("{50dd5230-ba8a-11d1-bf5d-0000f805f530}");
			
		} catch (Exception e) {
			return null;
		}
	}
	
	private List<Device> lookupDevices(String guid) throws Exception {
		List<Device> deviceList = this.getAllDevices();
		
		if (deviceList == null)
			return null;
		
		for (Iterator<Device> it = deviceList.iterator(); it.hasNext(); )
	        if (!guid.equals(it.next().getClassGuid()))
	            it.remove();
		
		return deviceList;
	}
	
}
